﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using Entities.IRepository;
using BLToolkit.Data;
using BLToolkit.Data.Linq;

namespace DAL.Admin
{
   public class BLTBoPhanRepository:ConnectionStringBL, IBoPhanRepository
    {
       //private DbManager db = new DbManager("QuanLiBongDa");
      
       
      
       public bool ThemBoPhan(BoPhan bp)
       {
           try
           {
             int kq=  db.Insert(bp);
               db.CommitTransaction();
               return kq > 0;

           }
           catch (Exception)
           {

               db.RollbackTransaction();
               return false;
           }
       }

       public bool CapNhatBoPhan(BoPhan bp)
       {
           try
           {
               int kq = db.Update(bp);
               db.CommitTransaction();
               return kq > 0;

           }
           catch (Exception)
           {

               db.RollbackTransaction();
               return false;
           }
       }

       public bool XoaBoPhan(BoPhan bp)
       {
           try
           {
               int kq = db.Delete(bp);
               db.CommitTransaction();
               return kq > 0;

           }
           catch (Exception)
           {

               db.RollbackTransaction();
               return false;
           }
       }

       public BoPhan LayTheoId(string id)
       {
           return db.GetTable<BoPhan>().SingleOrDefault(x => x.MaBoPhan == id);
       }

       public BoPhan LayChiTietTheoId(string id)
       {
           throw new NotImplementedException();
       }

       public List<BoPhan> LayTatCa()
       {
           return db.GetTable<BoPhan>().ToList();
       }
    }
}
